package com.vancouver.knows.business.tracker;

import com.pangu.task.IResultReceiver;
import com.pangu.task.OperateResult;
import com.vancouver.knows.business.BSharedPrefManager;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.bean.UserInfo;

/**
 * 获取用户查询列表
 *
 * @author llf
 *
 */
public class QueryUserInfoTracker extends ABInvokeTracker {

	public QueryUserInfoTracker(BusinessModule module, IResultReceiver resultReceiver) {
		super(module, resultReceiver);
	}

	@Override
	public String TAG() {
		return QueryUserInfoTracker.class.getSimpleName();
	}

	@Override
	public void handleResult(OperateResult result) {
		UserInfo userInfo = (UserInfo) result.getResultData();
		if (userInfo == null)
			return;

		BSharedPrefManager sharedPrefManager = new BSharedPrefManager(imContext);
		if (sharedPrefManager.getUserId() != null && sharedPrefManager.getUserId().equals(userInfo.getUserID())) {
			UserInfo localUserInfo = module.getCacheManager().getUserInfo();
			localUserInfo.setUserID(userInfo.getUserID());
			localUserInfo.setTotalUnReadPostComment(userInfo.getTotalUnReadPostComment());
			localUserInfo.setTotalUnReadComment(userInfo.getTotalUnReadComment());
			localUserInfo.setUserPostsCount(userInfo.getUserPostsCount());
			localUserInfo.setUserPostsWatchingCount(userInfo.getUserPostsWatchingCount());
			localUserInfo.setRegisterType(userInfo.getRegisterType());
			localUserInfo.setUserMeta(userInfo.getUserMeta());
			localUserInfo.setRegisterDate(userInfo.getRegisterDate());
			localUserInfo.userPointsDetailsInfo.setCommentPoints(userInfo.userPointsDetailsInfo.getCommentPoints());
			localUserInfo.userPointsDetailsInfo.setCommentUpvotePoints(userInfo.userPointsDetailsInfo.getCommentUpvotePoints());
			localUserInfo.userPointsDetailsInfo.setPointsPolicy(userInfo.userPointsDetailsInfo.getPointsPolicy());
			localUserInfo.userPointsDetailsInfo.setPointsStore(userInfo.userPointsDetailsInfo.getPointsStore());
			localUserInfo.userPointsDetailsInfo.setPostPoints(userInfo.userPointsDetailsInfo.getPostPoints());
			localUserInfo.userPointsDetailsInfo.setPostUpvotePoints(userInfo.userPointsDetailsInfo.getPostUpvotePoints());
			localUserInfo.userPointsDetailsInfo.setRedeemedPoints(userInfo.userPointsDetailsInfo.getRedeemedPoints());
			localUserInfo.userPointsDetailsInfo.setTotalPoints(userInfo.userPointsDetailsInfo.getTotalPoints());
			localUserInfo.userPointsDetailsInfo.setUpvotePoints(userInfo.userPointsDetailsInfo.getUpvotePoints());
			localUserInfo.userPointsDetailsInfo.setImageSharePoints(userInfo.userPointsDetailsInfo.getImageSharePoints());

			sharedPrefManager.saveUserId(userInfo.getUserID());
			sharedPrefManager.saveTotalUnReadComment(userInfo.getTotalUnReadComment());
			sharedPrefManager.saveTotalUnReadPostComment(userInfo.getTotalUnReadPostComment());
			sharedPrefManager.saveTotalPostsCount(userInfo.getUserPostsCount());
			sharedPrefManager.saveTotalWatchingCount(userInfo.getUserPostsWatchingCount());
			sharedPrefManager.saveRegisterType(userInfo.getRegisterType());
			sharedPrefManager.saveUserMeta(userInfo.getUserMeta());
			sharedPrefManager.saveRegisterDate(userInfo.getRegisterDate());
			//积分明细
			sharedPrefManager.saveTotalPoints(userInfo.userPointsDetailsInfo.getTotalPoints());
			sharedPrefManager.savePostPoints(userInfo.userPointsDetailsInfo.getPostPoints());
			sharedPrefManager.saveUpvotePoints(userInfo.userPointsDetailsInfo.getUpvotePoints());
			sharedPrefManager.saveCommentPoints(userInfo.userPointsDetailsInfo.getCommentPoints());
			sharedPrefManager.savePostUpvotePoints(userInfo.userPointsDetailsInfo.getPostUpvotePoints());
			sharedPrefManager.saveCommentUpvotePoints(userInfo.userPointsDetailsInfo.getCommentUpvotePoints());
			sharedPrefManager.saveRedeemedPoints(userInfo.userPointsDetailsInfo.getRedeemedPoints());
			sharedPrefManager.savePointsPolicy(userInfo.userPointsDetailsInfo.getPointsPolicy());
			sharedPrefManager.savePointsStore(userInfo.userPointsDetailsInfo.getPointsStore());
			sharedPrefManager.savePointsImage(userInfo.userPointsDetailsInfo.getImageSharePoints());

			module.getCacheManager().setUserInfo(localUserInfo);
		} else {
			module.getCacheManager().putUserInfo(userInfo);
		}
	}

}
